package com.dems.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dems.dao.RepairDao;
import com.dems.dao.StudentDao;
import com.dems.domain.Repair;
import com.dems.domain.Student;


@WebServlet("/SaveRepairServlet")
public class SaveRepairServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    private RepairDao repairDao = new RepairDao();
    private StudentDao studentDao = new StudentDao();

    public SaveRepairServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取参数
    	String studentNum = request.getParameter("studentNum");
        String repairType = request.getParameter("repairType");
        String repairDescription = request.getParameter("repairDescription");
        //根据账号查询学生信息
        Student student = studentDao.selectOne(studentNum);
        String repairState = "等待维修";
        String buildingId = student.getBuildingId();
        String studentName = student.getStudentName();
        String studentPhone = student.getStudentPhone();
        String studentDormitory = student.getStudentDormitory();
        Repair repair = new Repair(0,repairType,repairDescription,repairState,buildingId,studentNum
                        ,studentName,studentPhone,studentDormitory);
        repairDao.saveRepair(repair);
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}

